<template>
  <el-main>
    <!--
    搜索栏
    使用了element ui的form表单(:属性名是v-bind的缩写，用来动态绑定属性)
    model绑定自己写的数据模型 inline:行内样式 size:默认尺寸
     -->
    <el-form :model="listParm" :inline="true" size="default">
      <!--搜索框区域，绑定数据模型是-->
      <el-form-item>
        <el-input
            v-model="listParm.roleName"
            placeholder="请输入角色名称"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="searchBtn" :icon="Search">搜索</el-button>
          <el-button @click="resetBtn" :icon="Close" type="danger" plain>重置</el-button>
          <el-button type="primary" @click="addBtn" :icon="Plus">新增</el-button>
      </el-form-item>
    </el-form>
    <!-- 表格 -->
    <el-table :height="tableHeight" :data="tableList.list" border stripe>
      <el-table-column prop="roleName" label="角色名称"></el-table-column>
      <el-table-column prop="remark" label="角色描述"></el-table-column>
        <el-table-column  label="操作" width="220" align="center">
          <template #default="scope">
            <el-button type="primary" :icon="Edit" size="default"
                       @click="editBtn(scope.row)">编辑</el-button>
            <el-button type="danger" :icon="Delete"
                       size="default" @click="deleteBtn(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
          @size-change="sizeChange"
          @current-change="currentChange"
          :current-page.sync="listParm.currentPage"
          :page-sizes="[10,20, 40, 80, 100]"
          :page-size="listParm.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listParm.total" background>
      </el-pagination>
      <!-- 新增、编辑弹框 -->
      <role-add ref="addRef" @refresh="refresh"></role-add>
  </el-main>
</template>
<script setup lang="ts">
import RoleAdd from "./RoleAdd.vue";
import { Plus, Edit, Delete, Search, Close } from "@element-plus/icons-vue";
import useTable from "@/composables/role/useTable";
import useRole from "@/composables/role/useRole";
//表格相关的业务
const { listParm, getList, searchBtn,
        resetBtn,tableList,sizeChange,
        currentChange,tableHeight,refresh} = useTable();

//增删改查业务
const { addBtn, editBtn, deleteBtn,addRef } = useRole(getList);
</script>
<style scoped></style>